<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="oauthClientDetailsAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="add">{{$ti18('rxList.newBtn','新建')}}
                        </rx-button>
						<rx-button v-if="editEnable && selectedRowKeys.length > 0" alias="oauthClientDetailsEdit" :butn-icon="'edit'" :butn-type="'primary'"
								   :show-no-right="false" @click="editOne">{{$ti18('rxList.editBtn','编辑')}}
						</rx-button>
						<rx-button v-if="removeEnable && selectedRowKeys.length > 0" alias="oauthClientDetailsDelete" :butn-icon="'delete'" :butn-type="'danger'"
								   :show-no-right="false" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}
						</rx-button>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.clientName','应用名称')">
                            <a-input :placeholder="i18n('form.clientName','请输入应用名称','input')" v-model="queryParam['Q_A.client_name_S_LK']"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.clientId','应用ID')">
                            <a-input :placeholder="i18n('form.clientId','请输入应用ID','input')" v-model="queryParam['Q_A.client_id_S_LK']"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.createByName','创建人')">
                            <a-input :placeholder="i18n('form.createByName','创建人名称','input')" v-model="queryParam['Q_A.CREATE_BY_NAME__S_LK']"/>
                        </a-form-item>
                        <a-form-item :label="i18n('list.createTime','创建时间')+ i18n('list.from','从')">
                            <a-date-picker
                                style="width: 100%"
                                :placeholder="i18n('list.createTime','创建时间')"
                                v-model="queryParam['Q_A.CREATE_TIME__D_GT']"
                                format="YYYY-MM-DD"
                            />
                        </a-form-item>
                        <a-form-item :label="i18n('list.to','至')">
                            <a-date-picker
                                style="width: 100%"
                                :placeholder="i18n('list.endTime','结束时间')"
                                v-model="queryParam['Q_A.CREATE_TIME__D_LT']"
                                format="YYYY-MM-DD"
                            />
                        </a-form-item>
                        <a-form-item :label="i18n('form.enable','启用状态')">
                            <a-select v-model="queryParam['Q_A.ENABLE__S_EQ']" style="width: 100%">
                                <a-select-option value="1">{{i18n('isDefaultMap.yes','是')}}</a-select-option>
                                <a-select-option value="0">{{i18n('isDefaultMap.no','否')}}</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-user/user/org/oauthClientDetails/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="enable" slot-scope="{ text, record }">
                        <a-tag :color="enableMap[text].color">
                          <span>{{ enableMap[text].text }}</span>
                        </a-tag>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span v-if="editEnable && showBtn(true)" @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                        <span v-if="removeEnable && showBtn(true) && record.isDefault=='0'" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import OauthClientDetailsApi from '@/api/auth/oauthClientDetails'
import OauthClientDetailsEdit from './OauthClientDetailsEdit'
import {BaseList, RxFit, RxGrid,Util} from "@lowcode/jpaas-common-lib";

export default {
    name: 'OauthClientDetailsList',
    mixins: [BaseList],
    components: {
        RxFit
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 50,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.clientName','应用名称'), dataIndex: 'clientName', width: 100},
                {title: this.i18n('form.clientId','应用标识'), dataIndex: 'clientId', width: 100},
                {title: this.i18n('form.redirectUri','回调地址'), dataIndex: 'webServerRedirectUri', width: 150},
                {title: this.i18n('form.Validity','有效期'), dataIndex: 'accessTokenValidity', width: 80},
                {title: this.i18n('form.createByName','创建人'), dataIndex: 'createByName', width: 80},
                {title: this.i18n('form.enable','启用'), dataIndex: 'enable', width: 80, scopedSlots: {customRender: 'enable'}},
                {title: this.$ti18('rxList.action','操作'), width: 150, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ],
            component: OauthClientDetailsEdit,
            comment: this.i18n('list.comment','外部应用'),
            widthHeight: ['1200px', '700px'],
            fitSearch: false,
            enableMap: {
                "1": { color: 'green', text: this.i18n('enableMap.enable','启用') },
                "0": { color: 'red', text: this.i18n('enableMap.disable','禁用') }
            },
            isDefaultMap: {
                "1": { color: 'red', text: this.i18n('isDefaultMap.yes','是') },
                "0": { color: 'green', text: this.i18n('isDefaultMap.no','否') }
            },
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"oauthClientDetails",key);
        },
        delById(ids) {
            return OauthClientDetailsApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return OauthClientDetailsApi.query(parameter)
        }
    }
}
</script>
<style scoped>
.table-operator {
    padding: 4px;
}

.table-operator button {
    margin: 2px;
}
</style>

